<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title> - 注册</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/custom.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">


</head>

<body class="gray-bg">

<div class="middle-box text-center loginscreen   animated fadeInDown">
    <div>
        <div>

            <h1 class="logo-name"></h1>
            <img class="logo-name" src="img/医生头像.png" height="180px" width="180px"/>
        </div>
        <br/>
        <h3>修改信息</h3>

        <form class="m-t" role="form" action="login.html" style="text-align: left;">
            <div class="form-group">
                <a style="font-size: 15px; color: black;">姓名</a><a style="color: red;">*</a>
                <input type="text" id="name" class="form-control" placeholder="请输入姓名" required="">
            </div>
            <div class="form-group">
                <a style="font-size: 15px; color: black;">身份证号</a><a style="color: red;">*</a>
                <input type="text" id="card" class="form-control" placeholder="请输入身份证号" required="">
            </div>
            <div class="form-group">
                <a style="font-size: 15px; color: black;">密码</a><a style="color: red;">*</a>
                <input type="text" id="password" class="form-control" placeholder="请输入密码" required="">
            </div>
            <div class="form-group">
                <a style="font-size: 15px; color: black;">年龄</a><a style="color: red;">*</a>
                <input type="number" id="age" class="form-control" placeholder="请输入年龄" required="">
            </div>
            <div class="form-group">
                <a style="font-size: 15px; color: black;">性别</a><a style="color: red;">*</a>
                <div class="form-group">
                    <select class="form-control" id="sex">
                        <option>请选择性别</option>
                        <option value="0">男</option>
                        <option value="1">女</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <a style="font-size: 15px; color: black;">科室</a><a style="color: red;">*</a>
                <select class="form-control" id="room">
                    <option>请选择科室</option>
                    <option value="儿科">儿科</option>
                    <option value="妇科">妇科</option>
                    <option value="男科">男科</option>
                    <option value="外科">外科</option>
                    <option value="内科">内科</option>
                    <option value="五官科">五官科</option>
                </select>
            </div>

            <br>
            <button type="button" id="submit" onclick="register()" class="btn btn-primary block full-width m-b">确认修改
            </button>
            <a style="float: right; " data-toggle="modal" class="btn btn-primary" href="/admin-doc.html">返回</a>

        </form>
    </div>
</div>

<!-- 全局js -->
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.6"></script>
<!-- iCheck -->
<!--<script src="js/plugins/iCheck/icheck.min.js"></script>-->
<script src="./js/index.js"></script>
<script>


    var appointmentInfo = null;


    $(document).ready(function () {
        selectADoc();
    });

    function selectADoc() {
        var ids = window.location.search;
        console.log(ids);
        //将返回的字符串以=分割
        var id = ids.split("=")[1].trim();
        console.log(id);
        $.ajax({
            async: false,
            type: "post",
            url: "/selectADoc",
            data: JSON.stringify({id: id}),
            contentType: 'application/json',
            dataType: "text",
            success: function (data) {
                var result = JSON.parse(data);
                console.log(result);
                if (result.SUCCESS) {
                    appointmentInfo = result.RESULT;
                    afterInfo();
                } else {
                    console.log(result.RESULT);
                }
            },
            error: function (data) {
                alert("请求失败");
            }
        });
    }

    function afterInfo() {
        var name = $("#name");
        var age = $("#age");
        var sex = $("#sex");
        var password = $("#password");
        var card = $("#card");
        var room = $("#room");
        name.val(appointmentInfo.name);
        age.val(appointmentInfo.age);
        password.val(appointmentInfo.password);
        card.val(appointmentInfo.card);
        $("#sex").find("option[value='" + appointmentInfo.sex + "']").attr("selected", true);
        $("#room").find("option[value='" + appointmentInfo.room + "']").attr("selected", true);
    }


    function register() {
        var name = $("#name").val().trim();
        var password = $("#password").val().trim();
        var card = $("#card").val().trim();
        var sex = $("#sex").val().trim();
        var age = $("#age").val().trim();
        var numAge = parseInt(age);
        var room = $("#room").val().trim();
        if (name == null) {
            alert("请输入名字！");
            return false;
        }
        if (room == null) {
            alert("科室不可为空！");
            return false;
        }
        if (card == null || card.length != 18) {
            alert("身份证不符合规范！");
            return false;
        }
        if (sex == null || (sex != 0 && sex != 1)) {
            alert("请输入性别！");
            return false;
        }
        if (age != null) {
            if (numAge < 0 && numAge >= 150) {
                alert("请输入正确年龄！");
                return false;
            }
        } else {
            alert("请输入年龄！");
            return false;
        }
        $.ajax({
            async: true,
            type: "post",
            url: "/updateDoc",
            data: JSON.stringify(getQueryData()),
            contentType: 'application/json',
            dataType: "text",
            success: function (data) {
                var result = JSON.parse(data);
                console.log(result);
                if (result.SUCCESS) {
                    alert(result.RESULT);
                    window.location.href = "/admin-doc.html";
                } else {
                    alert(result.RESULT);
                }
            },
            error: function (data) {
                alert("请求失败");
            }
        });

    }


    function getQueryData() {

        var ids = window.location.search;
        console.log(ids);
        //将返回的字符串以=分割
        var id = ids.split("=")[1].trim();

        var dto = {};
        dto["id"] = id;
        if (!ifEmpty($("#name").val())) {
            dto["name"] = $("#name").val().trim();
        }
        if (!ifEmpty($("#card").val())) {
            dto["card"] = $("#card").val().trim();
        }
        if (!ifEmpty($("#room").val())) {
            dto["room"] = $("#room").val().trim();
        }
        if (!ifEmpty($("#age").val())) {
            dto["age"] = $("#age").val().trim();
        }
        if (!ifEmpty($("#sex").val())) {
            dto["sex"] = $("#sex").val().trim();
        }
        if (!ifEmpty($("#password").val())) {
            dto["password"] = $("#password").val().trim();
        }
        return dto;
    }


</script>


</body>

</html>
